package com.zsc.wxm.ysh.anjo.es.mqlisten;

import com.zsc.wxm.ysh.anjo.es.service.UploadService;
import com.zsc.wxm.ysh.anjo.service.base.config.RabbitMqConfig;
import com.zsc.wxm.ysh.anjo.service.base.model.mq.MqMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * ES监听消息队列
 *
 * @author playmaker
 */
@Slf4j(topic = "ES监听消息队列")
@Component
public class MqMessageListenerHandle {

    @Resource
    private UploadService uploadService;

    @RabbitListener(queues = RabbitMqConfig.ES_QUEUE)
    public void handle(MqMessage message) throws IOException {
        if (MqMessage.CREATE_OR_UPDATE.equals(message.getType())) {
            //接收到新增、更新消息
            uploadService.createOrUpdateData(message.getHouseId());
        } else if (MqMessage.DELETE.equals(message.getType())) {
            //接收到删除消息
            uploadService.removeData(message.getHouseId());
        }
    }
}
